#ifndef __CURL_UTIL_H__
#define __CURL_UTIL_H__

#include <curl/curl.h>

class EnvironmentInitializer
{
  public:
    EnvironmentInitializer(const EnvironmentInitializer &) = delete;
    EnvironmentInitializer &operator=(const EnvironmentInitializer &) = delete;
    EnvironmentInitializer(EnvironmentInitializer &&) = delete;
    EnvironmentInitializer &operator=(EnvironmentInitializer &&) = delete;

    static EnvironmentInitializer &instance()
    {
        static EnvironmentInitializer evn;
        return evn;
    }

  private:
    EnvironmentInitializer() { curl_global_init(CURL_GLOBAL_ALL); }

    ~EnvironmentInitializer() { curl_global_cleanup(); }
};

// 减少curl的init, cleanup操作
struct CURLhandle
{
    CURL *handle;
    CURLhandle() : handle(curl_easy_init()) {}
    ~CURLhandle()
    {
        if (handle)
            curl_easy_cleanup(handle);
    }
    // 重载它，后续使用CURL*会很方便
    operator CURL *() const { return handle; }
};

#endif  //__CURL_UTIL_H__